package com.lyb.springbootredisclient.infra;

import com.lyb.springbootredisclient.entity.User;
import com.lyb.springbootredisclient.mapper.UserMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author: lyb  2022/8/26 10:27
 */
public class AsyncInsertExecute implements Runnable {

    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    private User user;
    private UserMapper userMapper;
    private List<User> userList;


    public AsyncInsertExecute(User user, UserMapper userMapper, List<User> userList) {
        this.user = user;
        this.userMapper = userMapper;
        this.userList = userList;
    }


    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        if (CollectionUtils.isNotEmpty(userList)){
            SqlSession sqlSession = this.sqlSessionFactory.openSession(ExecutorType.BATCH, false);

        }
    }
}
